﻿using System;
using System.ComponentModel;
using System.Windows.Media;
using System.Collections.Generic;
using MyFloridaHouse.libSvBingMapsMultiShape;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;


namespace MyFloridaHouse.libSvOpenDistricts.Districts
{
    public class District : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        private int _districtID = 0;
        public int districtID
        {
            get { return _districtID; }
            set { if (_districtID != value) { _districtID = value;  } }
        }

        private bool _isLocked = false;
        public bool isLocked 
        {
            get { return _isLocked; } 
            set 
            { 
                if (_isLocked != value )
                {
                    _isLocked = value;
                    NotifyPropertyChanged("isLocked"); 
                }
            }
        }

        private bool _isContiguous = true;
        public bool isContiguous
        {
            get { return _isContiguous; }
            set
            {
                if (_isContiguous != value)
                {
                    _isContiguous = value;
                    NotifyPropertyChanged("isContiguous");
                }
            }
        }

        private bool _hasHole = false;
        public bool hasHole
        {
            get { return _hasHole; }
            set
            {
                if (_hasHole != value)
                {
                    _hasHole = value;
                    NotifyPropertyChanged("hasHole");
                }
            }
        }        
        
        private bool _isSelected = false;
        public bool isSelected
        {
            get { return _isSelected; }
            set
            {
                if (_isSelected != value)
                {
                    _isSelected = value;
                    NotifyPropertyChanged("isSelected");
                }
            }
        }

        

        private string _displayName = "";
        public string displayName
        {
            get { return _displayName; }
            set { if (_displayName != value) { _displayName = value; } }
        }



        private DateTime _lastChangedTimeStamp = new DateTime();
        public DateTime lastChangedTimeStamp
        {
            get { return _lastChangedTimeStamp; }
            set { if (_lastChangedTimeStamp != value) { _lastChangedTimeStamp = value; } }
        }

        private int _targetPopulation = 0;
        public int targetPopulation
        {
            get { return _targetPopulation; }
            set { if (_targetPopulation != value) { _targetPopulation = value; } }
        }


        public SolidColorBrush fillColorBrush
        {
            get
            {
                return DistrictColors.GetBrushFromIndex(districtID);
            }
        }

        private List<DistrictSubShapeMetadata> _subShapeMetadataList = new List<DistrictSubShapeMetadata>();
        public List<DistrictSubShapeMetadata> subShapeMetadataList
        {
            get { return _subShapeMetadataList; }
            set { if (_subShapeMetadataList != value) { _subShapeMetadataList = value; } }
        }


        private List<DistrictSubShapeMetadata> _subShapeHoleMetadataList = new List<DistrictSubShapeMetadata>();
        public List<DistrictSubShapeMetadata> subShapeHoleMetadataList
        {
            get { return _subShapeHoleMetadataList; }
            set { if (_subShapeHoleMetadataList != value) { _subShapeHoleMetadataList = value; } }
        }

        private BoundingBoxDTO _boundingBox = new BoundingBoxDTO();
        public BoundingBoxDTO boundingBox
        {
            get { return _boundingBox; }
            set { if (_boundingBox != value) { _boundingBox = value; } }
        }

        private PointDTO _centerPoint = new PointDTO();
        public PointDTO centerPoint
        {
            get { return _centerPoint; }
            set { if (_centerPoint != value) { _centerPoint = value; } }
        }


        private MultiMapShapeBase _districtMultiMapShape;
        public MultiMapShapeBase districtMultiMapShape
        {
            get { return _districtMultiMapShape; }
            set { if (_districtMultiMapShape != value) { _districtMultiMapShape = value; } }
        }

        public District(int districtID, string displayName, int targetPopulation)
        {
            _districtID = districtID;
            _displayName = displayName;
            _targetPopulation = targetPopulation;

            _boundingBox = new BoundingBoxDTO();
            _boundingBox.northWest = new PointDTO();
            _boundingBox.southEast = new PointDTO();
            _boundingBox.northWest.latitude = 1.0;
            _boundingBox.northWest.longitude = -1.0;
            _boundingBox.southEast.latitude = 0.0;
            _boundingBox.southEast.longitude = 0.0;

            _centerPoint = new PointDTO();
            _centerPoint.latitude = 0.5;
            _centerPoint.longitude = -0.5;

            _subShapeMetadataList = new List<DistrictSubShapeMetadata>();
            _subShapeHoleMetadataList = new List<DistrictSubShapeMetadata>();

            _lastChangedTimeStamp = DateTime.Now;
            
            _districtMultiMapShape = new MapMultiGeometry();
            
        }

    }
}
